<template>
  <div>
    <el-dialog
      title="评分编辑"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose"
    >
      <el-form
        label-position="right"
        label-width="120px"
        :model="formLabelAlign"
      >
        <el-form-item label="项目名称：">
          <el-input v-model="formLabelAlign.name" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="分值：">
          <el-input v-model="formLabelAlign.score"></el-input>
        </el-form-item>
        <el-form-item label="及格线：">
          <el-input v-model="formLabelAlign.pass"></el-input>
        </el-form-item>
        <el-form-item label="满分线：">
          <el-input v-model="formLabelAlign.full"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapState } from "vuex";
import axios from "axios";
export default {
  components: {},
  props: {
    formLabelAlign: {
      default: () => {
        return {
          name: "",
          score: "",
          pass: "",
          full: "",
          gradeId: "",
        };
      },
    },
  },
  data() {
    return {
      dialogVisible: false,
      //   formLabelAlign: {
      //     name: "",
      //     score: "",
      //     pass: "",
      //     full: "",
      //   },
    };
  },
  computed: {
    ...mapState({}),
  },
  watch: {},
  beforeDestroy() {},
  created() {},
  methods: {
    handleClose() {
      this.dialogVisible = false;
      this.$message({
        type: "warning",
        message: "已取消编辑",
      });
    },
    openDialog() {
      this.dialogVisible = true;
    },
    submit() {
      let id = this.formLabelAlign.gradeId;
      let score = this.formLabelAlign.score;
      let pass = this.formLabelAlign.pass;
      let full = this.formLabelAlign.full;
      console.log(id, score, pass, full);
      axios
        .post("/api/user/updateGrade", {
          score,
          pass,
          full,
          id,
        })
        .then(() => {
          this.$message({
            type: "success",
            message: "编辑成功",
          });
          this.dialogVisible = false;
          axios.post("/api/user/selectGrade", {}).then((res) => {
            console.log(res);
            this.$emit("editGrade", res.data);
          });
        });
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.el-button {
  position: static !important;
}
/deep/ .el-dialog {
  .el-dialog__header {
    background: #143853 !important;
  }
  .el-dialog__title {
    color: #ffffff;
  }
  .el-dialog__body {
    color: #ffffff;
    padding-bottom: 20px;
    background: #0f2d43 !important;
  }
  .el-dialog__footer {
    padding-right: 40px;
    background: #0f2d43;
  }
  .el-form-item__label {
    color: #ffffff;
  }
  .el-input__inner {
    background: #0355a4 !important;
    border: none;
    color: #ffffff;
  }
}
</style>